/**
 * Responsive Table to Card View Library
 * Transforms HTML tables into modern, high-contrast mobile cards on screens <= 768px.
 * Palindrome Labs - Hostel Management System
 */

/* Baseline improvements for table containers */
.table-responsive,
.table-responsive-custom,
.dataTables_wrapper {
    transition: all 0.2s ease-in-out;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE VIEW CARD TRANSFORMATION (<= 768px)
   ══════════════════════════════════════════════════════════════ */
@media screen and (max-width: 768px) {
    /* Remove horizontal scroll container clipping on mobile */
    .table-responsive,
    .table-responsive-custom,
    .dataTables_wrapper {
        overflow-x: visible !important;
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
    }

    /* Transform table into block container */
    table.responsive-card-table,
    table.table,
    table.report-table,
    table.expenditure-table,
    .responsive-card-table {
        display: block !important;
        width: 100% !important;
        border: none !important;
        background: transparent !important;
        margin-bottom: 0 !important;
    }

    /* Hide standard horizontal table header */
    table.responsive-card-table thead,
    table.table thead,
    table.report-table thead,
    table.expenditure-table thead {
        display: none !important;
    }

    /* Transform tbody into flex card container */
    table.responsive-card-table tbody,
    table.table tbody,
    table.report-table tbody,
    table.expenditure-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.15rem !important;
        width: 100% !important;
    }

    /* Each row becomes a standalone card */
    table.responsive-card-table tbody tr,
    table.table tbody tr,
    table.report-table tbody tr,
    table.expenditure-table tbody tr {
        display: block !important;
        background: #ffffff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 14px !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03) !important;
        padding: 1.15rem 1.25rem !important;
        margin-bottom: 0 !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease !important;
        position: relative !important;
    }

    table.responsive-card-table tbody tr:hover,
    table.table tbody tr:hover,
    table.report-table tbody tr:hover,
    table.expenditure-table tbody tr:hover {
        border-color: #cbd5e1 !important;
        box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.08), 0 4px 6px -2px rgba(37, 99, 235, 0.04) !important;
        transform: translateY(-2px) !important;
    }

    /* Each cell becomes a row inside the card */
    table.responsive-card-table tbody td,
    table.table tbody td,
    table.report-table tbody td,
    table.expenditure-table tbody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.65rem 0 !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        text-align: right !important;
        font-size: 0.88rem !important;
        color: #1e293b !important;
        min-height: 38px !important;
        word-break: break-word !important;
    }

    /* Top cell (SI No or Title badge) styling */
    table.responsive-card-table tbody td:first-child,
    table.table tbody td:first-child,
    table.report-table tbody td:first-child,
    table.expenditure-table tbody td:first-child {
        padding-top: 0 !important;
        margin-bottom: 0.35rem !important;
        padding-bottom: 0.75rem !important;
        border-bottom: 2px solid #f1f5f9 !important;
    }

    /* Bottom cell (Row Total or Action button) styling */
    table.responsive-card-table tbody td:last-child,
    table.table tbody td:last-child,
    table.report-table tbody td:last-child,
    table.expenditure-table tbody td:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
        margin-top: 0.35rem !important;
        padding-top: 0.75rem !important;
        border-top: 1px dashed #e2e8f0 !important;
        font-weight: 700 !important;
    }

    /* Auto-generated column label on the left */
    table.responsive-card-table tbody td::before,
    table.table tbody td::before,
    table.report-table tbody td::before,
    table.expenditure-table tbody td::before {
        content: attr(data-label);
        display: inline-flex !important;
        align-items: center !important;
        font-weight: 600 !important;
        font-size: 0.78rem !important;
        color: #64748b !important;
        text-transform: uppercase !important;
        letter-spacing: 0.04em !important;
        text-align: left !important;
        margin-right: 1rem !important;
        flex-shrink: 0 !important;
    }

    /* Hide label if data-label is empty or not set */
    table.responsive-card-table tbody td[data-label=""]::before,
    table.responsive-card-table tbody td:not([data-label])::before {
        display: none !important;
    }

    /* ─── Grand Total / Footer Card Transformation ─── */
    table.responsive-card-table tfoot,
    table.table tfoot,
    table.report-table tfoot,
    table.expenditure-table tfoot {
        display: block !important;
        width: 100% !important;
        margin-top: 1.25rem !important;
    }

    table.responsive-card-table tfoot tr,
    table.table tfoot tr,
    table.report-table tfoot tr,
    table.expenditure-table tfoot tr {
        display: block !important;
        background: linear-gradient(135deg, #f8fafc 0%, #eff6ff 100%) !important;
        border: 2px solid #bfdbfe !important;
        border-radius: 14px !important;
        padding: 1.15rem 1.25rem !important;
        box-shadow: 0 6px 14px rgba(37, 99, 235, 0.08) !important;
        margin-bottom: 0 !important;
    }

    table.responsive-card-table tfoot td,
    table.table tfoot td,
    table.report-table tfoot td,
    table.expenditure-table tfoot td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.6rem 0 !important;
        border: none !important;
        border-bottom: 1px dashed #cbd5e1 !important;
        text-align: right !important;
        font-size: 0.9rem !important;
        font-weight: 700 !important;
        color: #1e293b !important;
    }

    table.responsive-card-table tfoot td:last-child,
    table.table tfoot td:last-child,
    table.report-table tfoot td:last-child,
    table.expenditure-table tfoot td:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
        margin-top: 0.4rem !important;
        padding-top: 0.85rem !important;
        border-top: 2px solid #93c5fd !important;
        font-size: 1.1rem !important;
        color: #1e3a8a !important;
    }

    table.responsive-card-table tfoot td::before,
    table.table tfoot td::before,
    table.report-table tfoot td::before,
    table.expenditure-table tfoot td::before {
        content: attr(data-label);
        display: inline-flex !important;
        align-items: center !important;
        font-weight: 700 !important;
        font-size: 0.8rem !important;
        color: #1e40af !important;
        text-transform: uppercase !important;
        letter-spacing: 0.04em !important;
        text-align: left !important;
        margin-right: 1rem !important;
        flex-shrink: 0 !important;
    }

    /* DataTable specific controls wrapping */
    .dataTables_length,
    .dataTables_filter,
    .dataTables_info,
    .dataTables_paginate {
        text-align: center !important;
        margin-bottom: 0.75rem !important;
    }

    .dataTables_paginate .pagination {
        justify-content: center !important;
        flex-wrap: wrap !important;
    }
}
